
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS沙箱</title>
</head>
<body>
    <p>Ikki</p>
    <div id = 'x'></div>
    <script>
        let shadowDom = x.attachShadow({ mode: 'open' }); //外界无法访问 shadow dom
        let pElement = document.createElement('p');
        pElement.innerHTML = 'hello world';
        let styleElement = document.createElement('style');
        styleElement.textContent = `
            p{color:red}
        `
        shadowDom.appendChild(pElement);
        shadowDom.appendChild(styleElement)
    </script>
</body>
</html>